//
//  ViewController.swift
//  UIPasteboardDemo
//
//  Created by dayu on 15/5/25.
//  Copyright (c) 2015年 dayu. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var sourceImageView: UIImageView!
    @IBOutlet weak var targetImageView: UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }

    @IBAction func panGestureTop(sender: UILongPressGestureRecognizer) {
        let itemPase = UIMenuItem(title: "复制", action: "copyImage");
        let itemTrans = UIMenuItem(title: "转发", action: "trans");
        let itemCollect = UIMenuItem(title: "收藏", action: "collect");
        let itemJoin = UIMenuItem(title: "加入", action: "join");
        let menuController = UIMenuController.sharedMenuController();
        menuController.menuItems = [itemPase,itemCollect,itemTrans,itemJoin];
        
        let location = sender.locationInView(sender.view);
        let menuLocation = CGRectMake(location.x, location.y, 0, 0);
        
        menuController.setTargetRect(menuLocation, inView: sender.view!);
        menuController.arrowDirection = UIMenuControllerArrowDirection.Down;
        menuController.setMenuVisible(true, animated: true);
    }
    
    @IBAction func panGestureBottom(sender: UILongPressGestureRecognizer) {
        let itemPase = UIMenuItem(title: "粘贴", action: "paste");
        let menuController = UIMenuController.sharedMenuController();
        menuController.menuItems = [itemPase];
        let location = sender.locationInView(sender.view);
        let menuLocation = CGRectMake(location.x, location.y, 0, 0);
        menuController.setTargetRect(menuLocation, inView: sender.view!);
        menuController.arrowDirection = UIMenuControllerArrowDirection.Down;
        menuController.setMenuVisible(true, animated: true);
    }
    
    override func canBecomeFirstResponder() -> Bool {
        return true;
    }
    
    func copyImage() {
        let pasteBoard = UIPasteboard(name: "com.dayu.demo", create: true);
        pasteBoard.image = self.sourceImageView.image;
    }

    func trans() {
        
    }
    
    func collect() {
        
    }
    
    func join() {
        
    }
    
    func paste() {
        let pasteBoard = UIPasteboard(name: "com.dayu.demo", create: true);
        self.targetImageView.image = pasteBoard.image;
    }
}

